package com.example.config;

import com.example.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2019/10/31 9:47
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 配置mvc拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置拦截所有请求
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**");
    }

    /**
     * 配置权限拦截器
     * @return
     */
    @Bean
    public AuthenticationInterceptor authenticationInterceptor(){
        return new AuthenticationInterceptor();
    }
}
